/*
 * wueasy - A Java Distributed Rapid Development Platform.
 * Copyright (C) 2017-2022 wueasy.com , All Rights Reserved.

 * Without permission, no one is allowed to use 
 * (including but not limited to: copying, disseminating,
 * displaying, mirroring, uploading, downloading in illegal ways);

 * Otherwise, legal liability will be investigated according to law.
 */
package com.wueasy.demo.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.wueasy.base.vo.PageVo;
import com.wueasy.base.vo.ResultVo;
import com.wueasy.demo.dto.test.TestAddDto;
import com.wueasy.demo.dto.test.TestEditDto;
import com.wueasy.demo.dto.test.TestIdDto;
import com.wueasy.demo.dto.test.TestQueryPageDto;
import com.wueasy.demo.service.TestService;
import com.wueasy.demo.vo.TestVo;

import jakarta.validation.Valid;
import reactor.core.publisher.Mono;

/**
 * test
 * @author: fallsea
 * @version 1.0
 */
@RestController
@RequestMapping("/test")
public class TestController
{
	@Autowired
	private TestService testService;
	
	/**
	 * 新增
	 * @author: fallsea
	 * @param dto
	 * @return
	 */
	@PostMapping(value = "/add", produces = MediaType.APPLICATION_JSON_VALUE)
	public Mono<ResultVo<Void>> add(@RequestBody @Valid TestAddDto dto) {
		testService.add(dto);
		return Mono.just(ResultVo.ok());
	}
	
	/**
	 * 修改
	 * @author: fallsea
	 * @param dto
	 * @return
	 */
	@PostMapping(value = "/edit",  produces = MediaType.APPLICATION_JSON_VALUE)
	public Mono<ResultVo<Void>> edit(@RequestBody @Valid TestEditDto dto) {
		testService.edit(dto);
		return Mono.just(ResultVo.ok());
	}
	
	
	/**
	 * 查询单个
	 * @author: fallsea
	 * @param dto
	 * @return
	 */
	@PostMapping(value = "/get",  produces = MediaType.APPLICATION_JSON_VALUE)
	public Mono<ResultVo<TestVo>> get(@RequestBody @Valid TestIdDto dto) {
		return Mono.just(ResultVo.ok(testService.get(dto)));
	}

	/**
	 * 删除
	 * @author: fallsea
	 * @param dto
	 * @return
	 */
	@PostMapping(value = "/delete", produces = MediaType.APPLICATION_JSON_VALUE)
	public Mono<ResultVo<Void>> delete(@RequestBody @Valid TestIdDto dto) {
		testService.delete(dto);
		return Mono.just(ResultVo.ok());
	}

	/**
	 * 分页
	 * @author: fallsea
	 * @param dto
	 * @return
	 */
	@PostMapping(value = "/queryPage", produces = MediaType.APPLICATION_JSON_VALUE)
	public Mono<ResultVo<PageVo<TestVo>>> queryPage(@RequestBody @Valid TestQueryPageDto dto) {
		return Mono.just(ResultVo.ok(testService.queryPage(dto)));
	}
	
}